#include "func.h"
#include <cstdlib>


int main()
{
    //1.socket
    int clientfd = socket(AF_INET,SOCK_STREAM,0);
    if(clientfd < 0){
        perror("socket");
        return EXIT_FAILURE;
    }

    //2.connect
    struct sockaddr_in serveraddr;
    memset(&serveraddr,0,sizeof(serveraddr));
    serveraddr.sin_family = AF_INET;
    serveraddr.sin_port = htons(8000);
    serveraddr.sin_addr.s_addr = inet_addr("127.0.0.1");
    int ret = connect(clientfd,(const struct sockaddr*)&serveraddr,sizeof(serveraddr));
    if(ret < 0){
        perror("connect");
        close(clientfd);
        return EXIT_FAILURE;
    }
    printf("connect success\n");

    const char* msg = "hello server !";
    ret = send(clientfd,msg,strlen(msg),0);
    printf("send %d bytes\n",ret);

    char buf[1024] = {0};
    ret = recv(clientfd,buf,sizeof(buf),0);
    printf("recv %d bytes, buf: %s\n",ret,buf);

    while(1);

    return 0;
}

